<?php
namespace wow\modelworld;
/**
 *
 *
 * @Entity
 * @Table(name="item_template")
 *
 */
class ItemTemplate{


	/**
	 * @Id @Column(type="integer", name="entry")
	 */
	public $entry;

	/**
	 * @Column(type="string", name="name")
	 */
	public $name;

	/**
	 * @Column(type="string", name="Quality")
	 */
	public $Quality;

	
	static public $qualityTable = array(
		0 => array('#9d9d9d', 'Poor'),
		1 => array('#ccc', 'Common'),
		2 => array('#1eff00', 'Uncommon'),
		3 => array('#0070dd', 'Rare'),
		4 => array('#a335ee', 'Epic'),
		5 => array('#ff8000', 'Legendary'),
		6 => array('#e5cc80', 'Artifact')
	);
	

	/**
	 *
	 * Enter description here ...
	 * @param unknown_type $realm
	 * @param unknown_type $name
	 * @return wow\modelworld\ItemTemplate
	 */
	static public function getItemTemplate($realm, $id){
		$em = \wow\model\dbcon\WorldDB::getEmFor($realm);
		$q = $em->getWorldEM()->createQuery('SELECT s FROM wow\modelworld\ItemTemplate s WHERE s.entry = ?1')
		->setParameter(1, $id);

		return $q->getOneOrNullResult();
	}

	
	public function getColor(){
		return ItemTemplate::$qualityTable[$this->Quality][0];
	}
	
	/**
	 *
	 * Enter description here ...
	 * @param unknown_type $realm
	 * @param unknown_type $name
	 * @return wow\modelworld\ItemTemplate
	 */
	static public function getItemTemplateByName($realm, $name){
		$em = \wow\model\dbcon\WorldDB::getEmFor($realm);
		$q = $em->getWorldEM()->createQuery('SELECT s FROM wow\modelworld\ItemTemplate s WHERE s.name = ?1')
		->setParameter(1, $name);

		return $q->getOneOrNullResult();
	}

}